package com.alan.libapi.business.dao;

import com.alan.libapi.api.ApiHttp;
import com.alan.libapi.api.ApiResponse;
import com.alan.libapi.api.Impl.ApiHttpImpl;
import com.alan.libapi.business.IBusinessHttp;
import com.alan.libapi.model.business.AppVersionInfo;
import com.alan.libapi.model.business.AreaInfo;
import com.alan.libapi.model.business.BankType;
import com.alan.libapi.model.business.BoundBankCard;
import com.alan.libapi.model.business.MySharedWifiProfit;
import com.alan.libapi.model.business.PaidRecord;
import com.alan.libapi.model.business.ResponsedDevice;
import com.alan.libapi.model.business.ResponsedToken;
import com.alan.libapi.model.business.SharedWifiInfo;
import com.alan.libapi.model.business.UserBoundDevice;
import com.alan.libapi.model.business.UserInfo;
import com.alan.libapi.model.business.UserPackageInfo;
import com.alan.libapi.model.business.UserPackageSituation;
import com.alan.libapi.model.business.UserSession;
import com.alan.libapi.model.business.UserToken;
import com.alan.libapi.model.business.WifiMonthProfit;
import com.alan.libapi.model.persistent.ModifyPwdType;

import java.util.List;

/**
 * @className: BusinessHttpImpl
 * @describtion: BusinessHttpImpl
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/4/17 18:30
 */
public class BusinessHttpImpl implements IBusinessHttp {

    private ApiHttp apiHttp;
    private static BusinessHttpImpl _instance;

    public BusinessHttpImpl() {
        super();
        apiHttp = ApiHttpImpl.getInstance();
    }

    public static BusinessHttpImpl getInstance() {
        if(_instance == null){
            _instance = new BusinessHttpImpl();
        }
        return _instance;
    }

    /**
     ******************************************************************************************************************
     *<-----------------------------------------以下为Get方式获取信息的API接口--------------------------------------->
     *******************************************************************************************************************
     */

    @Override
    public void getUserInfo(final UserSession userSession, CallbackListener<UserInfo> callbackListener) {
        BaseAsyncTaskThread<UserInfo> baseAsyncTaskThread = new BaseAsyncTaskThread<UserInfo>(callbackListener) {
            @Override
            protected ApiResponse<UserInfo> doInBackground() {
                return apiHttp.getUserInfo(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getNearbySharedWifiList(final UserSession userSession, final int areaId, final double longitude, final double latitude,
                                        CallbackListener<List<SharedWifiInfo>> callbackListener) {
        BaseAsyncTaskThread<List<SharedWifiInfo>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<SharedWifiInfo>>(callbackListener) {
            @Override
            protected ApiResponse<List<SharedWifiInfo>> doInBackground() {
                return apiHttp.getNearbySharedWifiList(userSession, areaId, longitude, latitude);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getUserBoundDevice(final UserSession userSession, CallbackListener<UserBoundDevice> callbackListener) {
        BaseAsyncTaskThread<UserBoundDevice> baseAsyncTaskThread = new BaseAsyncTaskThread<UserBoundDevice>(callbackListener) {
            @Override
            protected ApiResponse<UserBoundDevice> doInBackground() {
                return apiHttp.getUserBoundDevice(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getUserPackageSituation(final UserSession userSession, CallbackListener<UserPackageSituation> callbackListener) {
        BaseAsyncTaskThread<UserPackageSituation> baseAsyncTaskThread = new BaseAsyncTaskThread<UserPackageSituation>(callbackListener) {
            @Override
            protected ApiResponse<UserPackageSituation> doInBackground() {
                return apiHttp.getUserPackageSituation(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getMySharedWifiList(final UserSession userSession, CallbackListener<List<SharedWifiInfo>> callbackListener) {
        BaseAsyncTaskThread<List<SharedWifiInfo>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<SharedWifiInfo>>(callbackListener) {
            @Override
            protected ApiResponse<List<SharedWifiInfo>> doInBackground() {
                return apiHttp.getMySharedWifiList(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getSharedWifiInfo(final UserSession userSession, final int wifiId, CallbackListener<SharedWifiInfo> callbackListener) {
        BaseAsyncTaskThread<SharedWifiInfo> baseAsyncTaskThread = new BaseAsyncTaskThread<SharedWifiInfo>(callbackListener) {
            @Override
            protected ApiResponse<SharedWifiInfo> doInBackground() {
                return apiHttp.getSharedWifiInfo(userSession, wifiId);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getMyAllSharedWifiProfitList(final UserSession userSession, CallbackListener<List<MySharedWifiProfit>> callbackListener) {
        BaseAsyncTaskThread<List<MySharedWifiProfit>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<MySharedWifiProfit>>(callbackListener) {
            @Override
            protected ApiResponse<List<MySharedWifiProfit>> doInBackground() {
                return apiHttp.getMyAllSharedWifiProfitList(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getMySpecifyWifiProfitList(final UserSession userSession, final int wifiId, CallbackListener<List<WifiMonthProfit>> callbackListener) {
        BaseAsyncTaskThread<List<WifiMonthProfit>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<WifiMonthProfit>>(callbackListener) {
            @Override
            protected ApiResponse<List<WifiMonthProfit>> doInBackground() {
                return apiHttp.getMySpecifyWifiProfitList(userSession, wifiId);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getMyPaidList(final UserSession userSession, CallbackListener<List<PaidRecord>> callbackListener) {
        BaseAsyncTaskThread<List<PaidRecord>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<PaidRecord>>(callbackListener) {
            @Override
            protected ApiResponse<List<PaidRecord>> doInBackground() {
                return apiHttp.getMyPaidList(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getPackageInfoList(final UserSession userSession, CallbackListener<List<UserPackageInfo>> callbackListener) {
        BaseAsyncTaskThread<List<UserPackageInfo>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<UserPackageInfo>>(callbackListener) {
            @Override
            protected ApiResponse<List<UserPackageInfo>> doInBackground() {
                return apiHttp.getPackageInfoList(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getMyBoundBankCardList(final UserSession userSession, CallbackListener<List<BoundBankCard>> callbackListener) {
        BaseAsyncTaskThread<List<BoundBankCard>> baseAsyncTaskThread = new BaseAsyncTaskThread<List<BoundBankCard>>(callbackListener) {
            @Override
            protected ApiResponse<List<BoundBankCard>> doInBackground() {
                return apiHttp.getMyBoundBankCardList(userSession);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getAppVersion(final int appPlatform, CallbackListener<AppVersionInfo> callbackListener) {
        BaseAsyncTaskThread<AppVersionInfo> baseAsyncTaskThread = new BaseAsyncTaskThread<AppVersionInfo>(callbackListener) {
            @Override
            protected ApiResponse<AppVersionInfo> doInBackground() {
                return apiHttp.getAppVersion(appPlatform);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void getAreaIdByAddress(final UserSession userSession, final String country, final String province, final String city, final String district, CallbackListener<AreaInfo> callbackListener) {
        BaseAsyncTaskThread<AreaInfo> baseAsyncTaskThread = new BaseAsyncTaskThread<AreaInfo>(callbackListener) {
            @Override
            protected ApiResponse<AreaInfo> doInBackground() {
                return apiHttp.getAreaIdByAddress(userSession, country, province, city, district);
            }
        };
        baseAsyncTaskThread.execute();
    }

    /**
     *******************************************************************************************************************
     *<-----------------------------------------以下为Post方式提交信息的API接口--------------------------------------->
     ********************************************************************************************************************
     */

    @Override
    public void postPhoneToRegisterVerify(final String mobilePhone, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postPhoneToRegisterVerify(mobilePhone);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUserRegister(final String userName, final String userPassword, final String userPhone, final String verifyCode,
                                 CallbackListener<UserSession> callbackListener) {
        BaseAsyncTaskThread<UserSession> baseAsyncTaskThread = new BaseAsyncTaskThread<UserSession>(callbackListener) {
            @Override
            protected ApiResponse<UserSession> doInBackground() {
                return apiHttp.postUserRegister(userName, userPassword, userPhone, verifyCode);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUserLogin(final String userAccount, final String userPassword, CallbackListener<UserSession> callbackListener) {
        BaseAsyncTaskThread<UserSession> baseAsyncTaskThread = new BaseAsyncTaskThread<UserSession>(callbackListener) {
            @Override
            protected ApiResponse<UserSession> doInBackground() {
                return apiHttp.postUserLogin(userAccount, userPassword);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postPhoneToModifyPassword(final ModifyPwdType typeTag, final String userPhone, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postPhoneToModifyPassword(typeTag, userPhone);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postVerifyCodeToModifyPassword(final ModifyPwdType typeTag, final String userPhone, final String verifyCode, CallbackListener<UserToken> callbackListener) {
        BaseAsyncTaskThread<UserToken> baseAsyncTaskThread = new BaseAsyncTaskThread<UserToken>(callbackListener) {
            @Override
            protected ApiResponse<UserToken> doInBackground() {
                return apiHttp.postVerifyCodeToModifyPassword(typeTag, userPhone, verifyCode);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postNewPasswordToModifyLoginPassword(final int userId, final String userPassword, final String token, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postNewPasswordToModifyLoginPassword(userId, userPassword, token);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postBindDevice(final UserSession userSession, final String deviceMac, CallbackListener<ResponsedDevice> callbackListener) {
        BaseAsyncTaskThread<ResponsedDevice> baseAsyncTaskThread = new BaseAsyncTaskThread<ResponsedDevice>(callbackListener) {
            @Override
            protected ApiResponse<ResponsedDevice> doInBackground() {
                return apiHttp.postBindDevice(userSession, deviceMac);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUnbindDevice(final UserSession userSession, final int deviceId, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postUnbindDevice(userSession, deviceId);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postAddWifi(final UserSession userSession, final String wifiSSID, final String wifiPassword, final String wifiMac, final double wifiLongitude,
                            final double wifiLatitude, final int wifiAreaId, final String wifiAddress, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postAddWifi(userSession, wifiSSID, wifiPassword, wifiMac, wifiLongitude, wifiLatitude, wifiAreaId, wifiAddress);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postDeleteWifi(final UserSession userSession, final int wifiId, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postDeleteWifi(userSession, wifiId);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUpdateWifi(final UserSession userSession, final int wifiId, final String wifiSSID, final String wifiPassword, final double wifiLongitude,
                               final double wifiLatitude, final int wifiAreaId, final String wifiAddress, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postUpdateWifi(userSession, wifiId, wifiSSID, wifiPassword, wifiLongitude, wifiLatitude, wifiAreaId, wifiAddress);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postNewPasswordToModifyPayPassword(final int userId, final String userPassword, final String token, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postNewPasswordToModifyPayPassword(userId, userPassword, token);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postBuyPackage(final UserSession userSession, final int packageType, final int count, final float totalPrice, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postBuyPackage(userSession, packageType, count, totalPrice);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postBindBankCardForBankType(final UserSession userSession, final String accountNum, CallbackListener<BankType> callbackListener) {
        BaseAsyncTaskThread<BankType> baseAsyncTaskThread = new BaseAsyncTaskThread<BankType>(callbackListener) {
            @Override
            protected ApiResponse<BankType> doInBackground() {
                return apiHttp.postBindBankCardForBankType(userSession, accountNum);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postBindBankCardToVerifyIdentity(final UserSession userSession, final String cardholderName, final String cardholderPhone,
                                                 final String accountNum, final int bankType, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postBindBankCardToVerifyIdentity(userSession, cardholderName, cardholderPhone, accountNum, bankType);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postBindBankCardForVerifyCode(final UserSession userSession, final String cardholderPhone, final String accountNum,
                                              CallbackListener<ResponsedToken> callbackListener) {
        BaseAsyncTaskThread<ResponsedToken> baseAsyncTaskThread = new BaseAsyncTaskThread<ResponsedToken>(callbackListener) {
            @Override
            protected ApiResponse<ResponsedToken> doInBackground() {
                return apiHttp.postBindBankCardForVerifyCode(userSession, cardholderPhone, accountNum);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postBindBankCardWithVerifyCode(final UserSession userSession, final String cardholderPhone, final String accountNum,
                                               final String token, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postBindBankCardWithVerifyCode(userSession, cardholderPhone, accountNum, token);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUnbindBankCardForVerify(final UserSession userSession, final String payPassword, CallbackListener<ResponsedToken> callbackListener) {
        BaseAsyncTaskThread<ResponsedToken> baseAsyncTaskThread = new BaseAsyncTaskThread<ResponsedToken>(callbackListener) {
            @Override
            protected ApiResponse<ResponsedToken> doInBackground() {
                return apiHttp.postUnbindBankCardForVerify(userSession, payPassword);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUnbindBankCard(final UserSession userSession, final String accountNum, final String token, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postUnbindBankCard(userSession, accountNum, token);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postSetDefaultBankCard(final UserSession userSession, final String accountNum, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postSetDefaultBankCard(userSession, accountNum);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postOutMoney(final UserSession userSession, final String accountNum, final float outMoney, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postOutMoney(userSession, accountNum, outMoney);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postModifyUserName(final UserSession userSession, final String userName, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postModifyUserName(userSession, userName);
            }
        };
        baseAsyncTaskThread.execute();
    }

    @Override
    public void postUserFeedback(final UserSession userSession, final int appPlatform, final int appVersionCode, final String feedbackContent,
                                 final long time, CallbackListener<Void> callbackListener) {
        BaseAsyncTaskThread<Void> baseAsyncTaskThread = new BaseAsyncTaskThread<Void>(callbackListener) {
            @Override
            protected ApiResponse<Void> doInBackground() {
                return apiHttp.postUserFeedback(userSession, appPlatform, appVersionCode, feedbackContent, time);
            }
        };
        baseAsyncTaskThread.execute();
    }
}
